﻿using System.Xml.Linq;

namespace AzukiMap.Layer
{
    public class LayerXmlParser
    {
        public virtual MapLayer Parse(XElement layerXml)
        {
            string layerName = layerXml.Name.ToString();

            if (layerName == "BingLayer")
            {
                MapLayer layer = new BingLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "GsiLayer")
            {
                MapLayer layer = new GsiLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "KaMapLayer")
            {
                MapLayer layer = new KaMapLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "OpenStreetMapLayer")
            {
                MapLayer layer = new OpenStreetMapLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "YahooMapLayer")
            {
                MapLayer layer = new YahooMapLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "LocalVectorLayer")
            {
                MapLayer layer = new YahooMapLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "PostGisLayer")
            {
                MapLayer layer = new PostGisLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "RasterIndexLayer")
            {
                MapLayer layer = new RasterIndexLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "PostGisRasterIndexLayer")
            {
                MapLayer layer = new PostGisRasterIndexLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "RasterLayer")
            {
                MapLayer layer = new RasterLayer();
                layer.Parse(layerXml);
                return layer;
            }
            if (layerName == "WMSLayer")
            {
                MapLayer layer = new WMSLayer();
                layer.Parse(layerXml);
                return layer;
            }

            if (layerName == "LayerGroup")
            {
                MapLayer layer = new LayerGroup();
                layer.Parse(layerXml);
                return layer;
            }

            return null;
        }
    }
}